/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package tman.system.peer.tman;

import common.peer.PeerAddress;
import java.util.Comparator;

/**
 *
 * @author gianmariospacagna
 */
public class DistanceComparator implements Comparator<PeerAddress> {

    private PeerAddress ref;

    public DistanceComparator(PeerAddress ref) {
        this.ref = ref;
    }

    @Override
    public int compare(PeerAddress t, PeerAddress t1) {
        int distT = RingBuilder.distance(ref, t);
        int distT1 = RingBuilder.distance(ref, t1);

        if (distT < distT1) {
            return -1;
        } else if (distT == distT1) {
            return 0;
        } else {
            return 1;
        }

    }
}
